trò chơi Cannon Siege miễn phí
12.319 lượt xem;
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4
5 public class CannonBullet : MonoBehaviour {
6
7 public GameObject explosionEffect;
8 public bool isIdle;
9
10 private Rigidbody2D rigidBody2D;
11 private bool cannonShot, isExplode;
12
13 void Awake(){
14 rigidBody2D = GetComponent<Rigidbody2D> ();
15 }
16
17 // Use this for initialization
18 void Start () {
19 cannonShot = true;
20 }
21
22 // Update is called once per frame
23 void Update () {
24 if (GameplayController.instance.gameInProgress) {
25 if (cannonShot && rigidBody2D.velocity.sqrMagnitude <= 0) {
26 DestroyBullet ();
27 }
28 }
29
30
31 }
32
33 void DestroyBullet(){
34 Destroy (gameObject);
35 if (!isExplode) {
36 isExplode = true;
37 GameObject newExplosionEffect = Instantiate (explosionEffect, transform.position, Quaternion.identity) as GameObject;
38 Destroy (newExplosionEffect, 3f);
39 }
40 }
41
42
43
44
45
46 }
2 using System.Collections.Generic;
3 using UnityEngine;
4
5 public class CannonBullet : MonoBehaviour {
6
7 public GameObject explosionEffect;
8 public bool isIdle;
9
10 private Rigidbody2D rigidBody2D;
11 private bool cannonShot, isExplode;
12
13 void Awake(){
14 rigidBody2D = GetComponent<Rigidbody2D> ();
15 }
16
17 // Use this for initialization
18 void Start () {
19 cannonShot = true;
20 }
21
22 // Update is called once per frame
23 void Update () {
24 if (GameplayController.instance.gameInProgress) {
25 if (cannonShot && rigidBody2D.velocity.sqrMagnitude <= 0) {
26 DestroyBullet ();
27 }
28 }
29
30
31 }
32
33 void DestroyBullet(){
34 Destroy (gameObject);
35 if (!isExplode) {
36 isExplode = true;
37 GameObject newExplosionEffect = Instantiate (explosionEffect, transform.position, Quaternion.identity) as GameObject;
38 Destroy (newExplosionEffect, 3f);
39 }
40 }
41
42
43
44
45
46 }
Use this for initialization
Update is called once per frame